﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAO;

namespace BUS
{
    public class PhongBUS
    {
        public static int KtMaPhong(long maPhong)
        {
            long temp = PhongDAO.KtMaPhong(maPhong);

            if (temp == 0)
                return 1;
            return 0;
        }

        public static int KtTenPhong(string tenPhong)
        {
            int temp = PhongDAO.KtTenPhong(tenPhong);

            if (temp == 0)
                return 1;
            return 0;
        }

        public static int LapDanhMucPhong(PhongDTO phong)
        {
            long tp1 = 0, tp2 = 0;
            int temp = 0;

            tp1 = PhongBUS.KtMaPhong(phong.MaPhong);
            tp2 = PhongBUS.KtTenPhong(phong.TenPhong);

            if (tp1 == 1 && tp2 == 1)
                temp = PhongDAO.LapDanhMucPhong(phong);

            if (tp1 == 0)
                return -1;
            if (tp2 == 0)
                return -2;

            return temp;
        }

        public static List<PhongDTO> TraCuuTheoTenPhong(string tenPhong)
        {
            return PhongDAO.TraCuuTheoTenPhong(tenPhong);
        }

        public static List<PhongDTO> TraCuuTheoLoaiPhong(long maLoaiPhong)
        {
            return PhongDAO.TraCuuTheoLoaiPhong(maLoaiPhong);
        }

        public static List<PhongDTO> TraCuuPhongTrong()
        {
            return PhongDAO.TraCuuPhongTrong();
        }

        public static List<PhongDTO> TraCuuPhongDaMuon()
        {
            return PhongDAO.TraCuuPhongDaMuon();
        }

        public static List<PhongDTO> TraCuuTatCa()
        {
            return PhongDAO.TraCuuTatCa();
        }

        public static PhongDTO LayTTPTheoMP(long mP)
        {
            return PhongDAO.LayTTPTheoMP(mP);
        }

        public static int XoaP(long mP)
        {
            return PhongDAO.XoaP(mP);
        }

        public static long Update(PhongDTO Phong)
        {
            long tp;
            long tp2 = 0;

            tp = PhongBUS.KtTenPhong2(Phong.TenPhong);

            if (tp == Phong.MaPhong || tp == 0)
                tp2 = PhongDAO.Update(Phong);

            if (tp != Phong.MaPhong && tp != 0)
                return -1;
            return tp2;
        }

        public static long KtTenPhong2(string tenPhong)
        {
            long temp = PhongDAO.KtTenPhong2(tenPhong);

            return temp;
        }

        public static void UpdateTT(PhongDTO Phong)
        {
            PhongDAO.UpdateTT(Phong);
        }

        public static List<PhongDTO> TraCuuTheoTenKH(string tKH)
        {
            return PhongDAO.TraCuuTheoTenKH(tKH);
        }
    }
}
